package com.transfer.action;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.opensymphony.xwork2.Action;
import com.transfer.service.TransferService;

public class TransferAction implements Action {
	TransferService transService;
	private int id1;
	private int id2;
	private double money;

	public TransferAction() {
		BeanFactory bf = new ClassPathXmlApplicationContext("applicationContext.xml");
		transService = (TransferService) bf.getBean("transService");
	}

	public int getId1() {
		return id1;
	}

	public void setId1(int id1) {
		this.id1 = id1;
	}

	public int getId2() {
		return id2;
	}

	public void setId2(int id2) {
		this.id2 = id2;
	}

	public double getMoney() {
		return money;
	}

	public void setMoney(double money) {
		this.money = money;
	}

	public void setTransService(TransferService transService) {
		this.transService = transService;
	}

	@Override
	public String execute() throws Exception {
		if (transService.trans(id1, id2, money)) {
			return Action.SUCCESS;
		}
		return Action.ERROR;
	}

}
